<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Adminlog Controller
 * Build by Phuc Nguyen
 * Contact : nguyenvanphuc0626@gmail.com
 */

class Accountancy_model extends MY_Model{
	
	public function __construct(){
		parent::__construct();
		$this->table_name = 'book_ketoan';
	}

        public function init_data($right){
		return array(
                                array(
						'name' => 'id',
						'label' => $this->lang->line('number'),
						'width' => '2%',
						'sort'  => FALSE,
						'searchoptions' => FALSE
				),
				array(
						'name' => 'username',
						'label' => $this->lang->line('username'),
						'width' => '5%',
						'sort'  => FALSE,
						'searchoptions' => FALSE
				),array(
						'name' 	=> 'ship',
						'label' => $this->lang->line('ship'),
						'width' => '20%',
						'sort'  => FALSE,
						'searchoptions' => FALSE
				),
				array(
						'name' 	=> 'booking_place_code',
						'label' => $this->lang->line('booking_place_code'),
						'width' => '5%',
						'sort'  => FALSE,
						'searchoptions' => FALSE
				),
                                array(
						'name' 	=> 'airline',
						'label' => $this->lang->line('airline'),
						'width' => '10%',
						'sort'  => 'DESC',
						'searchoptions' => FALSE
				),
                                array(
						'name' 	=> 'booker',
						'label' => $this->lang->line('booker'),
						'width' => '5%',
						'sort'  => FALSE,
						'searchoptions' => FALSE
				),array(
						'name' 	=> 'ticketWorkers',
						'label' => $this->lang->line('ticketWorkers'),
						'width' => '5%',
						'sort'  => FALSE,
						'searchoptions' => FALSE
				),array(
						'name' 	=> 'real_fare',
						'label' => $this->lang->line('real_fare'),
						'width' => '5%',
						'sort'  => FALSE,
						'searchoptions' => FALSE
				),array(
						'name' 	=> 'createdTime',
						'label' => $this->lang->line('createdTime'),
						'width' => '5%',
						'sort'  => FALSE,
						'searchoptions' => FALSE
				)
		);
	}
	
	public function json_data($controller, $right){
		$this->datatables
		->select("tbl.*")
		->from($this->table_name.' AS tbl');
	
		$this->datatables->set_produce_output(false);
		$ouput = $datatables = $this->datatables->generate();
		unset($ouput['aaData']);
		$ouput['aaData'] = array();
                $count = 1;
                
		foreach($datatables['aaData'] as $item){
                        $booking            = json_decode($item['booking']);
                        $string             = '';
                        $i                  = 0;
                        while($i < count($booking)){
                            $string .= $booking[$i].'<br/>';
                            $i++;
                        }
                    
			$ouput['aaData'][] = array(
					$count++,
					$item['name'],
					$string,
                                        $item['booking_place_code'],
                                        $item['airline'],
                                        $item['booker'],
                                        ($item['ticket_workers'])?$item['ticket_workers']:'-----------',
                                        $this->bookinglib->my_number_format($item['real_fare'],2, ',', ','),
                                        date("d-m-Y H:i:s",strtotime($item['createdTime']))
			);
		}
	
		return json_encode($ouput);
	}

}